package com.dv.lession03;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
//udp其实是没有客服端和服务端的区别  只有接收端和发送端
public class udpClientDemo01 {
    public static void main(String[] args) throws Exception {
        //1建立一个socket
        DatagramSocket datagramSocket = new DatagramSocket();
        //2建包 发送内容 发送目标
        String msg="你好呀，小服！";
        InetAddress localhost = InetAddress.getByName("localhost");
        int port = 9090;
        DatagramPacket packet = new DatagramPacket(msg.getBytes(), 0, msg.getBytes().length,localhost, port);
        //3发送包
        datagramSocket.send(packet);
        //关闭流
    }
}
